<?php
session_start ();
include '../class/MMysql.php';

if (isset($_COOKIE["agent_id"]))
    $agent_id= $_COOKIE["agent_id"];

$mysql = new MMysql();
$res = $mysql
    ->where(array('agent_id'=>$agent_id,"del_flag"=>0))
    ->select('agent');

$error="";
if (isset ($_POST ['agent_name'] )) {
    $agent_name = $_POST ['agent_name'];
    $agent_tel = $_POST ['agent_tel'];
    $agent_email = $_POST ['agent_email'];

//    echo $agent_name;
//    echo $agent_tel;
//    echo $agent_email;

    if ($agent_name == "" || $agent_tel == "" || $agent_email == "" ) {
        $error = "<span class='error'>agent information is not null</span>";
    } else {
//        $first_name=$user_first_name;
//        $last_name=$user_last_name;
//        $email=$user_email;
//        $tel=$user_tel;
        $mysql = new MMysql();
        $res = $mysql
            ->where(array('agent_id'=>$agent_id,"del_flag"=>0))
            ->update('agent',array('agent_name'=>$agent_name,'agent_tel'=>$agent_tel,"agent_email"=>$agent_email));
        if ($res>0) {
            echo "<script type=text/javascript> window.wxc.xcConfirm('update success', window.wxc.xcConfirm.typeEnum.success); window.location.href='settings_page_edit.php';</script>";
        } else {

          echo "<script type=text/javascript>window.location.href='settings_page_edit.php';</script>";;
        }
    }
}
?>

<?php
  include '../base/layout.php';
?>

<body>

<?php
 include '../base/agentheader.php';
?>

<section style="width: 100%;">

    <?php
    include '../base/agentsidemenu.php';
    ?>

    <aside class="content">
        <div style="margin-top: 60px;position: relative;">

            <div style="height: 20px;">

                <div style="margin-top: 30px;margin-left: 100px;">
                 <span style="font-size: 30px;">
                        Settings
                 </span>
                </div>


        <form action="settings_page_edit.php" method="post">

            <div style="margin-top: 20px;margin-left: 100px;">
                <span class="user_info_span">
                    The company full name
                </span>
                <?php

                echo '<input class="user_info_input" name="agent_name" style="width:400px;" type="text" value="'.$res[0]['agent_name'].'">'
                ?>

            </div>

            <div style="margin-top: 20px;margin-left: 100px;">
                <span class="user_info_span">
                    Tel
                </span>
                <?php

                echo '<input class="user_info_input" name="agent_tel" style="width:400px;" type="text" value="'.$res[0]['agent_tel'].'">'
                ?>

            </div>

            <div style="margin-top: 20px;margin-left: 100px;">
                <span class="user_info_span">
                    Email
                </span>
                <?php
                echo '<input class="user_info_input" name="agent_email" style="width:400px;" type="text" value="'.$res[0]['agent_email'].'">'
                ?>

            </div>


        <div style="margin-top: 20px;margin-left: 100px;">

            <input class="btn" value="Confirm" type="submit" style="background-color: #2B2B2B;color:white;width: 100px;" />
            <?php
              echo $error;
            ?>
        </div>

        </form>

        <div style="margin-top: 60px;margin-left: 100px;">
                <span style="position: relative;line-height: 34px;font-size:20px;color: rgb(152,152,152);display: block;">
                    change my password
                </span>

            <input onclick="topassword()" type="text" class="form-control" style="margin-top: 10px;width: 400px;"
                   placeholder="click here to change my password">
        </div>

    </aside>

</section>

</body>
</html>

<script>
    function topassword() {

        window.location.href='settings_page_password.php';
    }
</script>

